<?php


function addPar($inEvent, $sn, $isMember, $inName){
	$name = '';
	if($isMember == false){
		$name = $inName;
	}else{
		$name = checkSN((int)$sn);
	}
	$checkIfReg = false;
	$key = getKey();
	$now = getdate();
	if($name != '' || $name != 0){
		$events = new SimpleXMLElement('events.xml', null, true);
		
		foreach($events as $event){
			
			$curEvent = $event['id'];
			
			if($curEvent == $inEvent){
				if($event['max'] < $event['cur']+1){
					addWaitListPar($inEvent, $sn, $name, $isMember);
					
				}else if($now[0] > $event['enddate']){
					return false;
				}else{
					foreach($event as $par){
						if($par['sn'] == (string)$sn){
							return false;
						}
					}
					if($checkIfReg == false){
						$newPar = $event->addChild('par');
						$newPar->addAttribute('sn', (string)$sn);
						$newPar->addAttribute('name', $name);
						$newPar->addAttribute('paid', 'Nej');
						if($isMember == false){
							$newPar->addAttribute('member','Nej');
							addPendingMember($sn,$name);
						}else{
							$newPar->addAttribute('member','Ja');
						}
						$event['cur'] = $event['cur']+1;
						$newPar->addAttribute('key', $key);

					}
				}
				break;
			}
		}
		return true;
	}else{
		return false;
	}
}

?>